<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>投票页面</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <#assign currentMenu="activity"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>投票页面</h1>
        </section>
        <section class="content">
            <div class="box" style="padding: 10px">
                <div class="row">

                    <div class="col-md-offset-4 col-md-8">
                        <h1>关于2020年度部门旅游活动投票</h1>
                    </div>
                    <div class="col-md-12">
                        <div class="panel panel-default container">
                            <div class="panel-body">
                                <form id="editForm" action="/activity/result" method="post">
                                    <div class="row">
                                        <div class="col-md-2">
                                            <div class="radio">
                                                <input type="hidden" name="id" value="${activity.id}">
                                                <label>
                                                    <#list items as i>
                                                    <#--给它的选项框带一个id然后他点击的时候你传一个id过去-->
                                                    <input type="radio" id="optionsRadios" name="optionsRadios" value="${i.activityItem.id}" data-did="${i.activityItem.id}">
                                                                    ${i.activityItem.content}
                                                </label>
                                                <br/>
                                                </#list>
                                            </div>
                                        </div>
                                    </div>
                                    <button type="button" class="btn btn-primary btn-submit" data-id="${activity.id}">提交</button>
                                </form>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<script>

   $('.btn-submit').click(function () {
        var id=$(this).data('id')
       console.log(id);

      var did=  $('#optionsRadios').val()
       console.log(did)

       $.post('/activity/saveOrUpdate',{id:id},function (data) {
           if(data.success) {
               Swal.fire({
                   title: '投票成功',
                   type: 'success',
               }).then(() => {
                   $('#editForm').submit()
               })
           }
           else {
               Swal.fire(
                   '草泥马',
                    '已经投票过了',
                   'error',
               )
           }
       })
   })
</script>
</body>
</html>
